﻿using Microsoft.AspNetCore.StaticFiles;

namespace CommonUtils
{
    //静态文件过滤器
    public class FilterOfStaticFile
    {
        private static void OnPrepareResponse(StaticFileResponseContext context)
        {
            (ReflectionUtil.GetSenderClassName() + "." + ReflectionUtil.GetSenderMethodName()
                + " FilterOfStaticFile: "
                      + context.Context.Request.Path).Print();
        }

        public static StaticFileOptions Options;

        static FilterOfStaticFile()
        {
            Options = new StaticFileOptions();
            Options.OnPrepareResponse = OnPrepareResponse;
        }

        public static void AddTo(WebApplication app)
        {
            app.UseStaticFiles(Options);
        }
    }
}